<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="robots" content="all" />
<meta name="author" content="msleft" />
<meta name="Copyright" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<title></title>
<link rel="Shortcut Icon" href="images/en/favicon.ico" type="image/x-icon" />
<link rel="Bookmark" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script type="text/javascript" src="js/jquery-1.2.6.pack.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<script type="text/javascript">
function state_change(objElement)
{
	var objCityName = "";
	var objSateName = "";
	if (jQuery(objElement).attr("name") == "state_billing")
	{
		objCityName = "city_billing";
		objSateName = "state_billing";
	}
	else
	{
		objCityName = "city_shipping";
		objSateName = "state_shipping";
	}
		
	jQuery.ajax({
		type: "POST",
		url: 'ajaxCitys.php',
		data: 'citys=1&id_state='+ jQuery("select[@name='" + objSateName + "']").val(),
		success: function(msg){ 
			//alert( "Data Saved: " +   msg ); 
			
			jQuery("select[@name='" + objCityName + "']").html(msg);
		} 
	});
}
			
jQuery(function(){
	jQuery("select[@name='country_shipping']").change(function(){
		if (jQuery(this).val() != 'cn')
		{
			// city.
			var shipping_html = jQuery("select[@name='city_shipping']").parent().html();
			if (shipping_html != null)
			{
				var objParent = jQuery("select[@name='city_shipping']").parent();
				if (shipping_html.indexOf('<select') > -1 || shipping_html.indexOf('<SELECT') > -1)
				{
					var re = /<select[^>]*>[\s\S]*?<\/select>/ig;
					shipping_html = shipping_html.replace(re, '<input type="text" name="city_shipping" value="" class="ce_text mobile" />');
					objParent.html(shipping_html);
				}
				
				// state.
				objParent = jQuery("select[@name='state_shipping']").parent();
				shipping_html = jQuery("select[@name='state_shipping']").parent().html();
				if (shipping_html.indexOf('<select') > -1 || shipping_html.indexOf('<SELECT') > -1)
				{
					var re = /<select[^>]*>[\s\S]*?<\/select>/ig;
					shipping_html = shipping_html.replace(re, '<input type="text" name="state_shipping" value="" class="ce_text mobile" />');
					objParent.html(shipping_html);
				}
			}
		}
		else
		{
			// get all the state and city.
			var strState = '<select class="state mobile" value="" name="state_shipping" onchange="state_change(this);"><option value=""> - please select -</option>';
	<?php
		foreach ($arrStates_all as $key=>$strSate)
		{	
			$strOptionState .= "<option value=\"".$key."\">$strSate</option>";
		}
	?>	
			strState += '<?php echo $strOptionState; ?>';
			strState += "</select>(optional)";
			
			var strCity = '<select class="state mobile" value="" name="city_shipping"><option value=""> - please select -</option>';
	<?php	
		$strOptionCity = "";
		foreach ($arrCitys_all as $key=>$strCity)
		{
			$strOptionCity .= "<option value=\"".$key."\">" . addslashes($strCity) . "</option>";
		}
	?>
			strCity += '<?php echo $strOptionCity; ?>';
			strCity += "</select>";
			
			// city.
			var shipping_html = jQuery("input[@name='state_shipping']").parent().html();
			if (shipping_html != null)
			{
				var objParent = jQuery("input[@name='state_shipping']").parent();
				var strReplace = "";
				//alert(shipping_html);
				if (shipping_html.toLowerCase().indexOf('<input') > -1)
					strReplace = shipping_html.substr(shipping_html.toLowerCase().indexOf('<input'));
				//alert(strReplace);
				shipping_html = shipping_html.replace(strReplace, strState);
				objParent.html(shipping_html);
				
				var shipping_html = jQuery("input[@name='city_shipping']").parent().html();
				var objParent = jQuery("input[@name='city_shipping']").parent();
				var strReplace = "";
				//alert(shipping_html);
				if (shipping_html.toLowerCase().indexOf('<input') > -1)
					strReplace = shipping_html.substr(shipping_html.toLowerCase().indexOf('<input'));
				//alert(strReplace);
				shipping_html = shipping_html.replace(strReplace, strCity);
				objParent.html(shipping_html);
			}
		}
		
		return false;
	});
	
	
	jQuery("input[@name='postcode_shipping']").blur(function(el){
		var _target = jQuery(el.target||el);
		if (_target.val() == ""){
			jQuery(".shipping_address .contactus_item").find("label[@for='postcode_shipping']").show();
		}else{
			jQuery(".shipping_address .contactus_item").find("label[@for='postcode_shipping']").hide();
		}
	});
	
	jQuery("input[@name='firstname_shipping']").blur(function(el){
		var _target = jQuery(el.target||el);
		if (_target.val() == ""){
			jQuery(".shipping_address .name_item").find("label[@for='firstname_shipping']").show();
		}else{
			jQuery(".shipping_address .name_item").find("label[@for='firstname_shipping']").hide();
		}
	});
	
	jQuery("input[@name='lastname_shipping']").blur(function(el){
		var _target = jQuery(el.target||el);
		if (_target.val() == ""){
			jQuery(".shipping_address .name_item").find("label[@for='lastname_shipping']").show();
		}else{
			jQuery(".shipping_address .name_item").find("label[@for='lastname_shipping']").hide();
		}
	});
	
	jQuery("input[@name='city_shipping']").blur(function(el){
		var _target = jQuery(el.target||el);
		if (_target.val() == ""){
			jQuery(".shipping_address .contactus_item").find("label[@for='city_shipping']").show();
		}else{
			jQuery(".shipping_address .contactus_item").find("label[@for='city_shipping']").hide();
		}
	});
	
	jQuery("input[@name='cellphone_shipping']").blur(function(el){
		var _target = jQuery(el.target||el);
		if (_target.val() == ""){
			jQuery(".shipping_address .contactus_item").find("label[@for='cellphone_shipping']").html("Please input your mobile number.");
			jQuery(".shipping_address .contactus_item").find("label[@for='cellphone_shipping']").show();
		}else{
			if (!/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(jQuery("input[@name='cellphone_shipping']").val()))
			{
				jQuery(".shipping_address .contactus_item").find("label[@for='cellphone_shipping']").html("Cellphone must be digits.");
				jQuery(".shipping_address .contactus_item").find("label[@for='cellphone_shipping']").show();
			}
			else
				jQuery(".shipping_address .contactus_item").find("label[@for='cellphone_shipping']").hide();
		}
	});
	
	jQuery("input[@name='btn_add_shipping']").click(function(){
		var is_validate = true;
		var val_firstname = true;
		var val_lastname = true;
		var val_street_1 = true;
		var val_postcode = true;
		var val_country = true;
		var val_state = true;
		var val_city = true;
		var val_mobile = true;
		var var_phone = true;
		var strSate = (jQuery("select[@name='country_shipping']").val() == 'cn') ? jQuery("select[@name='state_shipping']").val() : jQuery("input[@name='state_shipping']").val();
		var strCity = (jQuery("select[@name='country_shipping']").val() == 'cn') ? jQuery("select[@name='city_shipping']").val() : jQuery("input[@name='city_shipping']").val();
		
		/**
		 * validate columns
		 */
		/** first shipping address firstname. **/
		if (jQuery("input[@name='firstname_shipping']").val() == "")
		{
			val_firstname = false;
			jQuery(".shipping_address .name_item").find("label[@for='firstname_shipping']").show();
		}
		else
		{
			val_firstname = true;
			jQuery(".shipping_address .name_item").find("label[@for='firstname_shipping']").hide();
		}
		
		// last name.
		if (jQuery("input[@name='lastname_shipping']").val() == "")
		{
			val_lastname = false;
			jQuery(".shipping_address .name_item").find("label[@for='lastname_shipping']").show();
		}
		else
		{
			val_lastname = true;
			jQuery(".shipping_address .name_item").find("label[@for='lastname_shipping']").hide();
		}
		
		// street 1
		if (jQuery("input[@name='street_shipping']").val() == "")
		{
			val_street_1 = false;
			jQuery(".shipping_address .street_address").find("label[@for='street_shipping']").show();
		}
		else
		{
			val_street_1 = true;
			jQuery(".shipping_address .street_address").find("label[@for='street_shipping']").hide();
		}
		
		// post code.
		if (jQuery("input[@name='postcode_shipping']").val() == "")
		{
			val_postcode = false;
			jQuery(".shipping_address .contactus_item").find("label[@for='postcode_shipping']").show();
		}
		else
		{
			/*if (/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(jQuery("input[@name='postcode_shipping']").val()))
			{
				val_postcode = true;
				if (jQuery("input[@name='postcode_shipping']").val().length == 6)
				{
					val_postcode = true;
					jQuery(".shipping_address .contactus_item").find("label[@for='postcode_shipping']").hide();
				}
				else
				{
					val_postcode = false;
					jQuery(".shipping_address .contactus_item").find("label[@for='postcode_shipping']").html("The postcode must equal to 6 digits.");
					jQuery(".shipping_address .contactus_item").find("label[@for='postcode_shipping']").show();
				}
			}
			else
			{
				val_postcode = false;
				jQuery(".shipping_address .contactus_item").find("label[@for='postcode_shipping']").html("The postcode must be digits.");
				jQuery(".shipping_address .contactus_item").find("label[@for='postcode_shipping']").show();
			}*/
		}
		
		// country
		if (jQuery("select[@name='country_shipping']").val() == "")
		{
			val_country = false;
			jQuery(".shipping_address .contactus_item").find("label[@for='country_shipping']").show();
		}
		else
		{
			val_country = true;
			jQuery(".shipping_address .contactus_item").find("label[@for='country_shipping']").hide();
		}
		
		// state
		/*if (jQuery("select[@name='state_shipping']").html() != null)
		{
			jQuery(".shipping_address .contactus_item").find("label[@for='state_shipping']").html("Please select state.");
			if (jQuery("select[@name='state_shipping']").val() == "")
			{
				val_state = false;
				jQuery(".shipping_address .contactus_item").find("label[@for='state_shipping']").show();
			}
			else
			{
				val_state = true;
				jQuery(".shipping_address .contactus_item").find("label[@for='state_shipping']").hide();
			}
		}
		else
		{
			jQuery(".shipping_address .contactus_item").find("label[@for='state_shipping']").html("Please input state.");
			if (jQuery("input[@name='state_shipping']").val() == "")
			{
				val_state = false;
				jQuery(".shipping_address .contactus_item").find("label[@for='state_shipping']").show();
			}
			else
			{
				val_state = true;
				jQuery(".shipping_address .contactus_item").find("label[@for='state_shipping']").hide();
			}
		}*/
		
		// city
		if (jQuery("select[@name='city_shipping']").html() != null)
		{
			jQuery(".shipping_address .contactus_item").find("label[@for='city_shipping']").html("Please select city.");
			if (jQuery("select[@name='city_shipping']").val() == "")
			{
				val_city = false;
				jQuery(".shipping_address .contactus_item").find("label[@for='city_shipping']").show();
			}
			else
			{
				val_city = true;
				jQuery(".shipping_address .contactus_item").find("label[@for='city_shipping']").hide();
			}
		}
		else
		{
			jQuery(".shipping_address .contactus_item").find("label[@for='city_shipping']").html("Please input city.");
			if (jQuery("input[@name='city_shipping']").val() == "")
			{
				val_city = false;
				jQuery(".shipping_address .contactus_item").find("label[@for='city_shipping']").show();
			}
			else
			{
				val_city = true;
				jQuery(".shipping_address .contactus_item").find("label[@for='city_shipping']").hide();
			}
		}
		
		// mobile phone
		if (jQuery("input[@name='cellphone_shipping']").val() == "")
		{
			val_mobile = false;
			jQuery(".shipping_address .contactus_item").find("label[@for='cellphone_shipping']").show();
		}
		else
		{
			if (/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(jQuery("input[@name='cellphone_shipping']").val()))
			{
				val_mobile = true;
				jQuery(".shipping_address .contactus_item").find("label[@for='cellphone_shipping']").hide();
			}
			else
			{
				val_mobile = false;
				jQuery(".shipping_address .contactus_item").find("label[@for='cellphone_shipping']").html("Cellphone must be digits.");
				jQuery(".shipping_address .contactus_item").find("label[@for='cellphone_shipping']").show();
			}
		}
		
		if (jQuery("input[@name='telephone_shipping']").val() != "")
		{
			if (/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(jQuery("input[@name='telephone_shipping']").val()))
			{
				var_phone = true;
				jQuery(".shipping_address .contactus_item").find("label[@for='telephone_shipping']").hide();
			}
			else
			{
				var_phone = false;
				jQuery(".shipping_address .contactus_item").find("label[@for='telephone_shipping']").show();
			}
		}
		
		is_validate = (val_firstname && val_lastname && val_street_1 && val_postcode && val_country && val_state && val_city && val_mobile && var_phone) ? true : false;
		
		if (is_validate)
		{
			if (jQuery("input[@name='shipping_action']").val() == "edit")
			{
				jQuery.ajax({
					type: "POST",
					url: 'shipping_addr.php',
					data: 'action=' + jQuery("input[@name='shipping_action']").val() + '&id_addr=' + jQuery("input[@name='id_addr']").val() + '&firstname='+ jQuery("input[@name='firstname_shipping']").val() + '&lastname=' + jQuery("input[@name='lastname_shipping']").val() + '&default_address=0&street_shipping=' + jQuery("input[@name='street_shipping']").val() + '&street_2_shipping=' + jQuery("input[@name='street_2_shipping']").val() + '&postcode_shipping=' + jQuery("input[@name='postcode_shipping']").val() + '&city_shipping=' + strCity + '&state_shipping=' + strSate + '&country_shipping=' + jQuery("select[@name='country_shipping']").val() + '&cellphone_shipping=' + jQuery("input[@name='cellphone_shipping']").val() + '&telephone_shipping=' + jQuery("input[@name='telephone_shipping']").val(),
					success: function(msg){ //alert( "Data Saved: " +   msg );
						parent.location.href = parent.location;
					} 
				});
			}
			else
				jQuery.ajax({
					type: "POST",
					url: 'shipping_addr.php',
					data: 'action=' + jQuery("input[@name='shipping_action']").val() + '&firstname='+ jQuery("input[@name='firstname_shipping']").val() + '&lastname=' + jQuery("input[@name='lastname_shipping']").val() + '&default_address=0&street_shipping=' + jQuery("input[@name='street_shipping']").val() + '&street_2_shipping=' + jQuery("input[@name='street_2_shipping']").val() + '&postcode_shipping=' + jQuery("input[@name='postcode_shipping']").val() + '&city_shipping=' + strCity + '&state_shipping=' + strSate + '&country_shipping=' + jQuery("select[@name='country_shipping']").val() + '&cellphone_shipping=' + jQuery("input[@name='cellphone_shipping']").val() + '&telephone_shipping=' + jQuery("input[@name='telephone_shipping']").val() + '&gender=' + parent.$("input[@name='gender']").val() + '&email=' + parent.$("input[@name='email_hide']").val() + '&uid=' + parent.$("input[@name='uid']").val(),
					success: function(msg){ 
						//alert( "Data Saved: " +   msg ); 
						parent.location.href = parent.location;
					} 
				});
		}
		
		return false;
	});
	
	jQuery("select[@name='state_shipping']").change(function(){
		jQuery.ajax({
				type: "POST",
				url: 'ajaxCitys.php',
				data: 'citys=1&id_state='+ jQuery("select[@name='state_shipping']").val(),
				success: function(msg){ 
					//alert( "Data Saved: " +   msg ); 
					
					jQuery("select[@name='city_shipping']").html(msg);
				} 
			});
	});
});	
</script>
<style type="text/css">
body {background:transparent;}
#tellfriend .msg_wrap div.error_container label.error
{
	display:none;
}
</style>
</head>
<body>
<div class="addressbook">
<div class="shipping_address">
<div class="msg_wrap">
<div class="name_item">
	<p>
		<label>FIRST NAME</label><input type="text" name="firstname_shipping" value="<?php echo $firstName; ?>" class="ce_text" />
		<label for="firstname_shipping" class="error" style="display:none;">Please input your first name.</label>
		<label>LAST NAME</label><input type="text" name="lastname_shipping" value="<?php echo $lastName; ?>" class="ce_text" />
		<label for="lastname_shipping" class="error" style="display:none;">Please input your last name.</label>
	</p>
</div>
<div class="street_address">
	<p>
		<input type="text" name="street_shipping" value="<?php echo ($street) ? $street : 'Address line 1'; ?>" onfocus="if (this.value == 'Address line 1') {this.value = '';}" onblur="if (this.value == ''){this.value = 'Address line 1'; }" class="ce_text address_text" />
		<label for="street_shipping" class="error" style="display:none;">Please input your address line 1.</label>
		<input type="text" name="street_2_shipping" value="<?php echo ($street_2) ? $street_2 : 'Address line 2'; ?>" onfocus="if (this.value == 'Address line 2') {this.value = '';}" onblur="if (this.value == ''){this.value = 'Address line 2'; }" class="ce_text address_text" />
	</p>	
	</div>
	
	<div class="contactus_item">
		<p>
			<label>ZIPCODE</label><input type="text" name="postcode_shipping" value="<?php echo $postcode; ?>" class="ce_text mobile" />
			<label for="postcode_shipping" class="error" style="display:none;">Please input your post code.</label>
		</p>
		<p>
			<label>COUNTRY</label>
			<select class="country mobile" name="country_shipping">
			<?php		
				
				$index = 0;
				foreach ($countries as $key=>$strCountry)
				{
			?>
			<?php if ($index == 0): ?>
				<option value=""> - please select -</option>
			<?php endif; ?>				
				<option value="<?php echo $key; ?>"<?php if ($key == $currentCountry || (!$currentCountry && $key == 'us')): ?> selected="selected"<?php endif; ?>><?php echo $strCountry; ?></option>			
			<?php
					$index++;
				}
			?>
			</select>
			<label for="country_shipping" class="error" style="display:none;">Please select country.</label>
		</p>
		<p>
			<label>STATE</label>
			<?php if (!$currentCountry || ($currentCountry && $currentCountry != 'cn')): ?>
			<input type="text" name="state_shipping" value="<?php echo $currentStates; ?>" class="ce_text mobile" />(optional)			
			<?php else: ?>
			<select name="state_shipping" value="" class="city mobile" />
			<?php 
				$index = 0;
				foreach ($arrStates as $key=>$strStatesInfo)
				{
			?>
				<?php if ($index == 0): ?>
				<option value=""<?php if (!isset($currentStates) || !$currentStates): ?> selected="selected"<?php endif; ?>> - please select -</option>';
				<?php else: ?>				
					<option value="<?php echo $key; ?>"<?php if ($key == $currentStates): ?> selected="selected"<?php endif; ?>><?php echo $strStatesInfo; ?></option>
				<?php endif; ?> 
			<?php
					$index++;
				}
			?>
			</select>(optional)
			<?php endif; ?>
		</p>
		<label for="state_shipping" class="error" style="display:none;">Please select state.</label>
		<p>
			<label>CITY</label>
			<?php if (!$currentCountry || ($currentCountry && $currentCountry != 'cn')): ?>
			<input type="text" name="city_shipping" value="<?php echo $currentCity; ?>" class="ce_text mobile" />
			<?php else: ?>
			<select name="city_shipping" value="" class="state mobile">
			<?php
				$index = 0;
				foreach ($arrCitys as $key=>$strCity)
				{
			?>
				<?php if ($index == 0): ?>
				<option value=""<?php if (!isset($currentCity) || !$currentCity): ?> selected="selected"<?php endif; ?>> - please select -</option>';
				<?php else: ?>	
				<option value="<?php echo $key; ?>"<?php if ($key == $currentCity): ?> selected="selected"<?php endif; ?>><?php echo $strCity; ?></option>
				<?php endif; ?> 
			<?php 
					$index++;
				}
			?>
			</select>
			<?php endif; ?>
		</p>
		<label for="city_shipping" class="error" style="display:none;">Please select city.</label>			
	</div>		
	
	<div class="contactus_item">
		<p>
			<label>MOBILE</label><input type="text" name="cellphone_shipping" value="<?php echo $cellphone; ?>" class="ce_text mobile" />
			<label for="cellphone_shipping" class="error" style="display:none;">Please input your mobile number.</label>
		</p>
		<p>
			<label>TELEPHONE</label><input type="text" name="telephone_shipping" value="<?php echo $telephone; ?>" class="ce_text mobile" />
			<label for="telephone_shipping" class="error" style="display:none;">Phone number must be digits.</label>
		</p>
	</div>
	<input type="hidden" name="shipping_action" value="<?php echo $form_action; ?>" />
	<input type="hidden" name="id_addr" value="<?php echo $id_addr; ?>" />
	<p class="submits"><input type="button" name="btn_add_shipping" value="<?php if ($id_addr): ?>EDIT ADDRESS <?php else: ?>ADD ADDRESS<?php endif; ?>" class="submit" /></p>
</div>
</div>  <!-- addresses end -->
</div>
</div> <!-- addressbook end -->
</body>
</html>